﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNetX
{
    /// <summary>
    /// A language
    /// </summary>
    public class Language
    {
        /// <summary>
        /// The name of this language
        /// </summary>
        public string Name
        {
            get
            {
                // return the name
                return this._name;
            }
            set
            {
                // set the name
                this._name = value;
            }
        }
        private string _name = string.Empty;

        /// <summary>
        /// The language code of this language
        /// </summary>
        public string Code
        {
            get
            {
                // return the code
                return this._code;
            }
            set
            {
                // set the code
                this._code = value;
            }
        }
        private string _code = string.Empty;

        /// <summary>
        /// The name of the country that this language belongs to
        /// </summary>
        public string CountryName
        {
            get
            {
                // return the country name
                return this._countryName;
            }
            set
            {
                // set the country name
                this._countryName = value;
            }
        }
        private string _countryName = string.Empty;

        /// <summary>
        /// The country this language belongs to
        /// </summary>
        public Country Country
        {
            get
            {
                // return the country
                return (from c in Countries.AllCountries
                        where c.Name.ToLower() == this.Name.ToLower()
                        select c).Single();
            }
        }

        /// <summary>
        /// Constructs this language
        /// </summary>
        /// <param name="name">The name of this language</param>
        /// <param name="code">The code of this language</param>
        /// <param name="countryName">The name of the country where this language is spoken</param>
        public Language(string name, string code, string countryName)
        {
            if (name == null)
                throw new ArgumentNullException("'name' is null.");
            if (name.Length == 0)
                throw new ArgumentOutOfRangeException("'name' is zero-length.");
            if (code == null)
                throw new ArgumentNullException("'code' is null.");
            if (code.Length == 0)
                throw new ArgumentOutOfRangeException("'code' is zero-length.");
            if (countryName == null)
                throw new ArgumentNullException("'countryName' is null.");
            if (countryName.Length == 0)
                throw new ArgumentOutOfRangeException("'countryName' is zero-length.");

            // set the values
            this.Name = name;
            this.Code = code;
            this.CountryName = countryName;
        }
    }
}
